package com.bigdata.spark.core.test

import java.io.ObjectInputStream
import java.net.ServerSocket

/**
 * P22: https://www.bilibili.com/video/BV11A411L7CK?p=22
 * P23: https://www.bilibili.com/video/BV11A411L7CK?p=23
 * 分布式计算模拟-搭建基础的架子
 */
object Executor2 {
  def main(args: Array[String]): Unit = {
    //启动服务器，接受数据
    val server = new ServerSocket(8888)
    println("服务器启动，等待接受数据...")
    //等待客户端的连接
    val client = server.accept()
    val in = client.getInputStream
    val objIn = new ObjectInputStream(in)

    //asInstanceOf 转换对象
    val task:SubTask = objIn.readObject().asInstanceOf[SubTask]
    val ints = task.compute()

    println("计算节点[8888]计算的结果：" + ints)
    in.close()
    client.close()
    server.close()
  }
}
